from django.utils import timezone
from django.conf import settings
import pytz
from rest_framework.pagination import PageNumberPagination
from rest_framework.views import Response
from fdfs_client.client import Fdfs_client
from rest_framework import serializers


def get_time_zero():
    """获取当地零时刻对应的格林时间  当地日期"""
    time_now = timezone.now()
    local_timezone = pytz.timezone(settings.TIME_ZONE)
    local_time = time_now.astimezone(tz=local_timezone)
    local_time_zero = local_time.replace(hour=0, minute=0, second=0)

    time_zero = time_now - (local_time - local_time_zero)  # 本地0时刻对应 经度0对应的时间
    return time_zero,local_time.date()


class PaginatorShow(PageNumberPagination):
    page_size = 5
    page_query_param = "page"
    page_size_query_param = "pagesize"
    max_page_size = 10

    def get_paginated_response(self, data):
        return Response({
            "count": self.page.paginator.count,
            "lists":data,
            "page":self.page.number,
            "pages":self.page.paginator.num_pages,
            "pagesize":self.request.query_params.get("pagesize")

        })


def storagePic(content):
    conn = Fdfs_client("./client.conf")
    ret = conn.upload_by_buffer(content)

    return ret
